package com.cosmos.codegen.utils;

import java.io.File;

/**
 * 文件操作工具类
 * 
 * @date 2016-3-22 10:02:24
 * @version 1.0
 * @author zhuzhaoyong
 *
 */
public class FileUtil {
	
	/**
	 * 递归删除文件夹以及文件
	 * @param dist
	 */
	public static void deleteFiles(File dist) {
		if(!dist.exists()) {
			return;
		}
		File parentFile = dist.getParentFile();
		if(parentFile == null) {
			return;
		}
		
		File[] listFiles = dist.listFiles();
		if(listFiles.length == 0) {
			dist.delete();
		} else {
			for(File file : listFiles) {
				if(file.isFile()) {
					file.delete();
				} else {
					deleteFiles(file);
				}
			}
			dist.delete();
		}
		deleteFiles(parentFile);
	}
}
